package com.crungoo;

import com.crungoo.order.comparator.A;
import com.crungoo.order.comparator.B;
import java.util.ArrayList;
import java.util.List;
import org.springframework.core.OrderComparator;

/**
 * Spring 提供的比较器
 *
 * @author fujc-dev@qq.com
 * @description TODO
 * @date 2023/6/28 12:40
 */
public class OrderComparatorPrograms {

	public static void main(String[] args) {
		A a = new A(); // order=3
		B b = new B(); // order=2

		OrderComparator comparator = new OrderComparator();
		System.out.println(comparator.compare(a, b));  // 1

		List list = new ArrayList<>();
		list.add(a);
		list.add(b);

		// 按order值升序排序
		list.sort(comparator);

		System.out.println(list);  // B，A
	}
}

